import { Entity } from "./Entity";

class CircleEntity extends Entity {
  velocity_dim = 8;
  size = 1;
  scale_size = 1.5;
  constructor(x: number, y: number, color: string) {
    super({
      type: "circle",
      color,
    });
    this.rect.x = x;
    this.rect.y = y;
    this.rect.w = this.size;
    this.rect.h = this.size;
    this.is_falling = false;
  }
  enterFrame() {
    this.scale_size *= 0.985;
    this.size += this.scale_size;
    this.rect.w = this.size;
    this.rect.h = this.size;
    this.move();
    this.draw();
  }
}

export class Circle {
  list: CircleEntity[] = [];
  add(x: number, y: number, color: string) {
    const circle = new CircleEntity(x, y, color);
    const alpha = 0.2;
    circle.alpha = alpha;
    this.list.push(circle);
  }
  enterFrame() {
    this.list.forEach((circle) => {
      circle.enterFrame();
      circle.alpha -= circle.velocity_dim * 1e-4;
      if (circle.alpha <= 0) {
        this.list = this.list.filter((o) => o !== circle);
      }
    });
  }
}
